package com.ay.shardingshere.controller;

import com.ay.shardingshere.entity.Order;
import com.ay.shardingshere.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.events.Event;

import java.util.List;
import java.util.Random;

/**
 * @Author: ay
 * @Date: 2021/6/24
 * @Description:
 **/
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 生成 0 或 1两个数
     * @return
     */
    private long getRandomNum(){
        return (long) (Math.random() * 2);
    }

    @PostMapping
    public void save(){
        for (int i =0; i< 50; i++){
            Order order = new Order();
            order.setUserId(getRandomNum());
            order.setAddress("北京");
            orderService.save(order);
        }
    }


    public List<Order> list(){
        return orderService.list();
    }
}


